<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="../css/weui.css"/>
    <link rel="stylesheet" href="../css/weuix.css"/>

    <script src="../js/zepto.min.js"></script>
    <script src="../js/zepto.weui.js"></script>
    <script src="../js/php.js"></script>
    <script>
        var loading = false;  //状态标记
        let start = 0
        let pagesize=15;
        let flag=true

        function ajaxpage(start1){
            $.ajax({
                type:"post",
                url:'/zanlist1',
                data: {"start":start1,"pagesize":pagesize},
                dataType:'json',
                timeout:10000,
                beforeSend:function(xhr){
                    $('.weui-loadmore').show();
                },
                success:function(rs){
                    if(rs.list==null){
                        $(".weui-loadmore").html("没有更多数据了");
                        return false
                    }
                    start = start1+count(rs.list)
                    if(count(rs.list)<pagesize){
                        flag=false//设置没有数据了标记
                        $(document.body).destroyInfinite();
                        $(".weui-loadmore").html("没有更多数据了");
                    }
                    $("#rank-list").append(tpl(document.getElementById('tpl').innerHTML,rs));
                },
                error:function(xhr){
                    alert('ajax出错');
                },
            });


        }

        $(function(){
            $(document.body).infinite(100).on("infinite", function() {
                if(loading) return;
                loading = true;
                setTimeout(function() {
                    if(flag){
                        ajaxpage(start)
                    }
                    loading = false;
                }, 1500);   //模拟延迟
            });

            var l = sessionStorage.getItem('index_list');
            if(null !== l && '' !== l){
                $("#rank-list").html(l);
                $(window).scrollTop(sessionStorage.getItem('index_scroll'));
                start = parseInt(sessionStorage.getItem('index_start'));
                sessionStorage.removeItem('index_list');
                sessionStorage.removeItem('index_page');
                sessionStorage.removeItem('index_scroll');
            }else{
                ajaxpage(0);
            }
        });
        const goto=(id)=>{
            sessionStorage.setItem('index_list',$("#rank-list").html());//存储列表数据
            sessionStorage.setItem('index_start',start);//存储页码
            sessionStorage.setItem('index_scroll',$(window).scrollTop());//存储滚动条位置
            location.href="js91.html?id="+id;
        }
    </script>
</head>

<body ontouchstart>

<div class="page-hd">
    <h1 class="page-hd-title">
        滚动加载
    </h1>
    <p class="page-hd-desc">插件方法实现,和非插件功能一样</p>
</div>

<div class="weui-cells"  id="rank-list">
    <script id="tpl" type="text/html">
        <% for(var i in list) {   %>
    <div class="weui-cell hand" data-id="<%=list[i].id%>" onclick="goto(<%=list[i].id%>)">
        <div class="weui-cell__bd">
            <p>ID: <%=list[i].id%>姓名: <%=list[i].zid%></p>
        </div>
        <div class="weui-cell__ft"><%=list[i].money%></div>
    </div>
        <% } %>
    </script>
</div>

<div class="weui-loadmore hide">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>


<br>
<br>
<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__links">
        <a href="../index.html" class="weui-footer__link">WeUI首页</a>
    </p>
    <p class="weui-footer__text">Copyright &copy; Yoby</p>
</div>
</body>
</html>
